/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package module5.exercise1;

/**
 *
 * @author trang
 */
public class TestArray {

    //        printArray Support Method;
    public  static void printArray(int [] array){
        System.out.print('<');
        for (int i = 0; i < array.length; i++) {
//          print an element
            System.out.print(array[i]);
//          print a comma delimiter if not the last element
            if ((i+1)<array.length){
                System.out.print(", ");
            }
        }
                System.out.println('>');

    }
    public static void main(String[] args) {
       
//        Simple Array
        int [] array1 = {2,3,5,7,11,13,17,19};
        int [] array2;

        System.out.print("Array 1 before assigning is : ");
        printArray(array1);

        array2=array1;
        for (int i = 0; i < array2.length; i++) {
            if (i%2==0) {
                array2[i]=i;
            } else {
                array2[i]=array1[i];
            }
        }

        System.out.print("Array 1 after assigning is : ");
        printArray(array1);

//        Multi Array
        int [][] matrix= new int [5][];
        for (int i = 0; i < matrix.length; i++) {
            matrix[i]=new int[i];
            for (int j = 0; j < matrix[i].length; j++) {
                matrix[i][j]=i*j;
            }
        }
        for (int i = 0; i < matrix.length; i++) {
                System.out.print("matrix [" + i + "] is ");
                printArray(matrix[i]);
        }

    }
}
